import {Component, OnInit} from '@angular/core';
import {CarService} from "../car.service";
import {FormBuilder} from "@angular/forms";

@Component({
  selector: 'app-car',
  templateUrl: './car.component.html',
  styleUrls: ['./car.component.css']
})
export class CarComponent implements OnInit {
  constructor(
    private carService: CarService,
    private formBuilder:FormBuilder
  ) {
  }

  items = this.carService.getItems()
  /**
   * 使用 FormBuilder 的 group() 方法
   * 把 checkoutForm 属性设置为
   * 包含 name 和 address 字段的表单模型。
   */
  checkoutForm =this.formBuilder.group({
  name:'',
  address:''
})

  onSubmit():void{
    this.items=this.carService.clearCart()
    console.warn('Your order has been submitted', this.checkoutForm.value);
    this.checkoutForm.reset();
  }
  ngOnInit(): void {
  }

}
